home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / ImageConvex / ImageConvex.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-11-06  |  11.0 KB  |  477 lines

  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Cursor;
  6. import java.awt.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.Image;
  10. import java.awt.MediaTracker;
  11. import java.awt.event.MouseEvent;
  12. import java.awt.event.MouseListener;
  13. import java.awt.image.MemoryImageSource;
  14. import java.awt.image.PixelGrabber;
  15. import java.net.MalformedURLException;
  16. import java.net.URL;
  17. import java.net.URLEncoder;
  18.  
  19. public class ImageConvex extends Applet implements Runnable, MouseListener {
  20.    boolean loaded;
  21.    Thread thread;
  22.    Image image;
  23.    Image buffer;
  24.    // $FF: renamed from: b java.awt.Graphics
  25.    Graphics field_0;
  26.    Color backColor;
  27.    // $FF: renamed from: wi int
  28.    int field_1;
  29.    // $FF: renamed from: he int
  30.    int field_2;
  31.    int wiIm;
  32.    int heIm;
  33.    int pause = 20;
  34.    static int[] pix;
  35.    static int[] pixnew;
  36.    int radius;
  37.    // $FF: renamed from: X int
  38.    int field_3;
  39.    // $FF: renamed from: Y int
  40.    int field_4;
  41.    int XStep;
  42.    int YStep;
  43.    float IConv;
  44.    float IConvStep;
  45.    float IConvMax;
  46.    int radiusStep;
  47.    int dimMin;
  48.    private String statusBarText;
  49.    private AudioClip sound;
  50.    private AudioClip clicSound;
  51.    private AudioClip enterSound;
  52.    private boolean loopSound;
  53.    private String link;
  54.    // $FF: renamed from: fm java.awt.FontMetrics
  55.    private FontMetrics field_5;
  56.    private String enterText;
  57.    private boolean isEnterTextEnabled;
  58.    private int wiEnterText;
  59.    private int enterTextHeight;
  60.    private Color enterTextColor;
  61.    private int decx;
  62.    private int decy;
  63.  
  64.    public String getAppletInfo() {
  65.       return "Name: ImageConvex\r\nAuthor: Taiji Software\r\n";
  66.    }
  67.  
  68.    public ImageConvex() {
  69.       this.backColor = Color.black;
  70.       this.IConv = 2.0F;
  71.       this.IConvStep = 0.5F;
  72.       this.IConvMax = 9.0F;
  73.       this.radius = 0;
  74.       this.radiusStep = 5;
  75.       ((Component)this).addMouseListener(this);
  76.    }
  77.  
  78.    public void register() {
  79.       try {
  80.          URL u = new URL("http://www.taijisoftware.com");
  81.          ((Applet)this).getAppletContext().showDocument(u, "_blank");
  82.          this.stop();
  83.       } catch (Exception e) {
  84.          System.out.println(e);
  85.          this.stop();
  86.       }
  87.    }
  88.  
  89.    public void init() {
  90.       String codeBase = null;
  91.  
  92.       try {
  93.          codeBase = (new URL(((Applet)this).getCodeBase().toString())).getHost();
  94.          System.out.println("Copyright 1999, 2001 Taiji Software(tm)\nYour domain name is : " + codeBase);
  95.          codeBase = codeBase.toUpperCase();
  96.       } catch (Exception var11) {
  97.       }
  98.  
  99.       if (!((Applet)this).getCodeBase().toString().toUpperCase().startsWith("FILE") || ((Applet)this).getParameter("debug") != null) {
  100.          String regCode = ((Applet)this).getParameter("registration_code");
  101.          if (regCode == null) {
  102.             regCode = ((Applet)this).getParameter("reg_domain");
  103.             if (regCode == null) {
  104.                this.register();
  105.             } else {
  106.                if (regCode.length() == codeBase.length() + 4 && !codeBase.startsWith("WWW.")) {
  107.                   codeBase = "WWW." + codeBase;
  108.                } else if (regCode.length() == codeBase.length() - 4 && codeBase.startsWith("WWW.")) {
  109.                   codeBase = codeBase.substring(4);
  110.                }
  111.  
  112.                char[] chars = new char[codeBase.length()];
  113.                codeBase.getChars(0, codeBase.length(), chars, 0);
  114.                String key = new String("haricot");
  115.                char[] chars2 = new char[key.length()];
  116.                key.getChars(0, key.length(), chars2, 0);
  117.  
  118.                for(int i = 0; i < codeBase.length(); ++i) {
  119.                   int j;
  120.                   if (i >= key.length()) {
  121.                      j = i - key.length() * (i / key.length());
  122.                   } else {
  123.                      j = i;
  124.                   }
  125.  
  126.                   chars[i] += chars2[j];
  127.                   chars[i] = (char)(chars[i] - chars[i] / 26 * 26 + 97);
  128.                }
  129.  
  130.                String res = new String(chars);
  131.                if (!res.equalsIgnoreCase(regCode)) {
  132.                   this.register();
  133.                }
  134.             }
  135.          } else if (!regCode.equals("settevercsedegnamiaj") && !regCode.equals("8078")) {
  136.             this.register();
  137.          }
  138.       }
  139.  
  140.       this.getParameters();
  141.       this.image = ((Applet)this).getImage(((Applet)this).getCodeBase(), ((Applet)this).getParameter("image_name"));
  142.       MediaTracker tracker = new MediaTracker(this);
  143.       tracker.addImage(this.image, 0);
  144.  
  145.       try {
  146.          tracker.waitForAll();
  147.          tracker.isErrorAny();
  148.       } catch (Exception e) {
  149.          System.err.println(e);
  150.       }
  151.  
  152.       if (!this.loaded) {
  153.          this.stop();
  154.       }
  155.  
  156.       this.wiIm = this.image.getWidth(this);
  157.       this.heIm = this.image.getHeight(this);
  158.       this.decx = (this.field_1 - this.wiIm) / 2;
  159.       this.decy = (this.field_2 - this.heIm) / 2;
  160.       pix = new int[this.wiIm * this.heIm];
  161.       pixnew = new int[this.wiIm * this.heIm];
  162.       PixelGrabber pixg = new PixelGrabber(this.image, 0, 0, this.wiIm, this.heIm, pix, 0, this.wiIm);
  163.  
  164.       try {
  165.          pixg.grabPixels();
  166.       } catch (InterruptedException var9) {
  167.       }
  168.  
  169.       this.image = ((Component)this).createImage(new MemoryImageSource(this.wiIm, this.heIm, pixnew, 0, this.wiIm));
  170.       this.buffer = ((Component)this).createImage(this.field_1, this.field_2);
  171.       this.field_0 = this.buffer.getGraphics();
  172.       this.field_0.setColor(this.enterTextColor);
  173.       String fontName = ((Applet)this).getParameter("enter_text_font");
  174.       if (fontName == null) {
  175.          fontName = "TimesRoman";
  176.       }
  177.  
  178.       int style = 1;
  179.       String s = ((Applet)this).getParameter("enter_text_style");
  180.       if (s != null) {
  181.          if (s.equals("bold")) {
  182.             style = 1;
  183.          } else if (s.equals("italic")) {
  184.             style = 2;
  185.          } else if (s.equals("bold_italic")) {
  186.             style = 3;
  187.          } else {
  188.             style = 0;
  189.          }
  190.       }
  191.  
  192.       this.field_0.setFont(new Font(fontName, style, this.enterTextHeight));
  193.       this.field_5 = this.field_0.getFontMetrics();
  194.       if (this.enterText != null) {
  195.          this.wiEnterText = this.field_5.stringWidth(this.enterText);
  196.       }
  197.  
  198.       this.field_3 = (int)((float)this.wiIm / 2.0F);
  199.       this.field_4 = (int)((float)this.heIm / 2.0F);
  200.       if (this.wiIm >= this.heIm) {
  201.          this.dimMin = this.heIm;
  202.       } else {
  203.          this.dimMin = this.wiIm;
  204.       }
  205.  
  206.       if (this.sound != null) {
  207.          if (this.loopSound) {
  208.             this.sound.loop();
  209.             return;
  210.          }
  211.  
  212.          this.sound.play();
  213.       }
  214.  
  215.    }
  216.  
  217.    public void getParameters() {
  218.       this.field_1 = ((Component)this).getSize().width;
  219.       this.field_2 = ((Component)this).getSize().height;
  220.       String s = ((Applet)this).getParameter("pause");
  221.       if (s != null) {
  222.          this.pause = Integer.parseInt(s);
  223.       }
  224.  
  225.       this.backColor = this.getColor("background_color");
  226.       ((Component)this).setBackground(this.backColor);
  227.       s = ((Applet)this).getParameter("radiusStep");
  228.       if (s != null) {
  229.          this.radiusStep = Integer.parseInt(s);
  230.       }
  231.  
  232.       s = ((Applet)this).getParameter("convexStep");
  233.       if (s != null) {
  234.          this.IConvStep = (float)((double)((float)Integer.parseInt(s)) / (double)100.0F);
  235.       }
  236.  
  237.       this.statusBarText = ((Applet)this).getParameter("status_bar_text");
  238.       s = ((Applet)this).getParameter("sound_name");
  239.       if (s != null) {
  240.          this.sound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  241.       }
  242.  
  243.       s = ((Applet)this).getParameter("loop_sound");
  244.       if (s != null) {
  245.          if (s.equals("yes")) {
  246.             this.loopSound = true;
  247.          } else {
  248.             this.loopSound = false;
  249.          }
  250.       }
  251.  
  252.       s = ((Applet)this).getParameter("clic_sound_name");
  253.       if (s != null) {
  254.          this.clicSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  255.       }
  256.  
  257.       s = ((Applet)this).getParameter("enter_sound_name");
  258.       if (s != null) {
  259.          this.enterSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  260.       }
  261.  
  262.       this.link = ((Applet)this).getParameter("link");
  263.       this.enterText = ((Applet)this).getParameter("enter_text");
  264.       s = ((Applet)this).getParameter("enter_text_height");
  265.       if (s != null) {
  266.          this.enterTextHeight = Integer.parseInt(s);
  267.       }
  268.  
  269.       this.enterTextColor = this.getColor("enter_text_color");
  270.       if (this.enterTextColor == null) {
  271.          this.enterTextColor = Color.white;
  272.       }
  273.  
  274.    }
  275.  
  276.    public Color getColor(String param) {
  277.       String s = ((Applet)this).getParameter(param);
  278.       if (s != null) {
  279.          if (s.substring(0, 1).equals("#")) {
  280.             s = s.substring(1);
  281.             int i = Integer.parseInt(s, 16);
  282.             return new Color(i);
  283.          } else {
  284.             return null;
  285.          }
  286.       } else {
  287.          return null;
  288.       }
  289.    }
  290.  
  291.    public void start() {
  292.       if (this.thread == null) {
  293.          this.thread = new Thread(this);
  294.          this.thread.start();
  295.       }
  296.  
  297.    }
  298.  
  299.    public void stop() {
  300.       if (this.thread != null) {
  301.          this.thread = null;
  302.       }
  303.  
  304.       if (this.sound != null) {
  305.          this.sound.stop();
  306.       }
  307.  
  308.    }
  309.  
  310.    public void run() {
  311.       Thread.currentThread().setPriority(4);
  312.  
  313.       while(true) {
  314.          ((Component)this).repaint();
  315.  
  316.          try {
  317.             Thread.sleep((long)this.pause);
  318.          } catch (InterruptedException var1) {
  319.          }
  320.  
  321.          this.calculatePixels();
  322.          this.radius += this.radiusStep;
  323.          if (this.radius >= this.dimMin - this.radiusStep || this.radius < 0) {
  324.             this.radiusStep = -this.radiusStep;
  325.          }
  326.  
  327.          this.IConv += this.IConvStep;
  328.          if (this.IConv >= this.IConvMax || this.IConv < 2.0F) {
  329.             this.IConvStep = -this.IConvStep;
  330.          }
  331.       }
  332.    }
  333.  
  334.    public final void paint(Graphics g) {
  335.       if (!this.loaded) {
  336.          this.field_0.setColor(Color.white);
  337.          this.field_0.drawString("loading... please wait", 1, this.field_2 / 2);
  338.          this.loaded = true;
  339.       } else {
  340.          if (this.image != null) {
  341.             this.field_0.clearRect(0, 0, this.field_1, this.field_2);
  342.             this.field_0.drawImage(this.image, this.decx, this.decy, this);
  343.             if (this.isEnterTextEnabled) {
  344.                this.field_0.drawString(this.enterText, (this.field_1 - this.wiEnterText) / 2, this.field_2 / 2);
  345.             }
  346.  
  347.             this.image = null;
  348.          }
  349.  
  350.          g.drawImage(this.buffer, 0, 0, this);
  351.       }
  352.    }
  353.  
  354.    public final void update(Graphics g) {
  355.       this.paint(g);
  356.    }
  357.  
  358.    private final void calculatePixels() {
  359.       for(int ii = 0; ii < this.heIm; ++ii) {
  360.          for(int jj = 0; jj < this.wiIm; ++jj) {
  361.             int i = jj - this.field_3;
  362.             int j = ii - this.field_4;
  363.             float r1 = (float)Math.sqrt((double)(i * i + j * j));
  364.             float r2 = 1.0F;
  365.             if (r1 < (float)this.radius) {
  366.                r2 = this.IConv - (this.IConv - 1.0F) * r1 / (float)this.radius;
  367.             }
  368.  
  369.             float r3 = (float)i / r2 + (float)this.field_3;
  370.             float r4 = (float)j / r2 + (float)this.field_4;
  371.             if (r1 < (float)this.radius) {
  372.                if (r3 > 0.0F && r3 < (float)(this.wiIm - 1) && r4 > 0.0F && r4 < (float)(this.heIm - 1)) {
  373.                   float r5 = r3 - (float)((int)r3);
  374.                   float r6 = r4 - (float)((int)r4);
  375.                   int a = (int)((1.0F - r5) * (1.0F - r6) * (float)this.pixel((int)r4, (int)r3, 16711680, 16) + (1.0F - r5) * r6 * (float)this.pixel((int)r4 + 1, (int)r3, 16711680, 16) + r5 * (1.0F - r6) * (float)this.pixel((int)r4, (int)r3 + 1, 16711680, 16) + r5 * r6 * (float)this.pixel((int)r4 + 1, (int)r3 + 1, 16711680, 16));
  376.                   int b = (int)((1.0F - r5) * (1.0F - r6) * (float)this.pixel((int)r4, (int)r3, 65280, 8) + (1.0F - r5) * r6 * (float)this.pixel((int)r4 + 1, (int)r3, 65280, 8) + r5 * (1.0F - r6) * (float)this.pixel((int)r4, (int)r3 + 1, 65280, 8) + r5 * r6 * (float)this.pixel((int)r4 + 1, (int)r3 + 1, 65280, 8));
  377.                   int c = (int)((1.0F - r5) * (1.0F - r6) * (float)this.pixel((int)r4, (int)r3, 255, 0) + (1.0F - r5) * r6 * (float)this.pixel((int)r4 + 1, (int)r3, 255, 0) + r5 * (1.0F - r6) * (float)this.pixel((int)r4, (int)r3 + 1, 255, 0) + r5 * r6 * (float)this.pixel((int)r4 + 1, (int)r3 + 1, 255, 0));
  378.                   pixnew[ii * this.wiIm + jj] = (new Color(a, b, c)).getRGB();
  379.                } else {
  380.                   pixnew[ii * this.wiIm + jj] = this.backColor.getRGB();
  381.                }
  382.             } else {
  383.                pixnew[ii * this.wiIm + jj] = pix[ii * this.wiIm + jj];
  384.             }
  385.          }
  386.       }
  387.  
  388.       this.image = ((Component)this).createImage(new MemoryImageSource(this.wiIm, this.heIm, pixnew, 0, this.wiIm));
  389.    }
  390.  
  391.    public final int pixel(int i, int j, int hex, int dec) {
  392.       return (pix[i * this.wiIm + j] & hex) >> dec;
  393.    }
  394.  
  395.    public URL giveURL(String url) {
  396.       try {
  397.          if (url.toUpperCase().startsWith("HTTP")) {
  398.             return new URL(url);
  399.          } else if (url.toUpperCase().startsWith("FTP")) {
  400.             int p = url.indexOf(":");
  401.             int p2 = url.indexOf(":", p + 1);
  402.             if (p2 != -1) {
  403.                url = url.substring(0, p + 3) + URLEncoder.encode(url.substring(p + 3, url.length()));
  404.             }
  405.  
  406.             p = url.indexOf("%40");
  407.             if (p != -1) {
  408.                url = url.substring(0, p) + "@" + url.substring(p + 3, url.length());
  409.             }
  410.  
  411.             return new URL(url);
  412.          } else {
  413.             return new URL(((Applet)this).getCodeBase(), url);
  414.          }
  415.       } catch (MalformedURLException e) {
  416.          System.out.println(e);
  417.          return null;
  418.       }
  419.    }
  420.  
  421.    public void mouseClicked(MouseEvent e) {
  422.    }
  423.  
  424.    public void mouseEntered(MouseEvent e) {
  425.       if (this.enterText != null) {
  426.          this.isEnterTextEnabled = true;
  427.          this.field_0.setColor(this.enterTextColor);
  428.          ((Component)this).repaint();
  429.       }
  430.  
  431.       if (this.statusBarText != null) {
  432.          ((Applet)this).showStatus(this.statusBarText);
  433.       }
  434.  
  435.       if (this.enterSound != null) {
  436.          this.enterSound.play();
  437.       }
  438.  
  439.       if (this.link != null) {
  440.          ((Component)this).setCursor(new Cursor(12));
  441.       }
  442.  
  443.    }
  444.  
  445.    public void mouseExited(MouseEvent e) {
  446.       if (this.isEnterTextEnabled) {
  447.          this.isEnterTextEnabled = false;
  448.          ((Component)this).repaint();
  449.       }
  450.  
  451.       if (this.link != null) {
  452.          ((Component)this).setCursor(new Cursor(0));
  453.       }
  454.  
  455.    }
  456.  
  457.    public void mousePressed(MouseEvent e) {
  458.       if (this.clicSound != null) {
  459.          this.clicSound.play();
  460.       }
  461.  
  462.       if (this.link != null) {
  463.          String target = ((Applet)this).getParameter("target");
  464.          if (target == null) {
  465.             target = "_blank";
  466.          }
  467.  
  468.          URL u = this.giveURL(this.link);
  469.          ((Applet)this).getAppletContext().showDocument(u, target);
  470.       }
  471.  
  472.    }
  473.  
  474.    public void mouseReleased(MouseEvent e) {
  475.    }
  476. }
  477.